home *** CD-ROM | disk | FTP | other *** search
- Path: unix.sri.com!usenet
- From: mklenk@updike.sri.com (Mark Klenk)
- Newsgroups: comp.lang.c
- Subject: Re: Q: realloc->free?
- Date: 16 Jan 1996 16:05:27 GMT
- Organization: Nuance Communications
- Message-ID: <4dgic7$qin@unix.sri.com>
- References: <4df2ud$706@oxy.rust.net>
- Reply-To: mklenk@updike.sri.com
- NNTP-Posting-Host: 204.75.161.40
-
-
- Earl Bennett wrote:
- >
- >realloc() will free the old block. It is perfectly legal to say
- >
- > a = realloc(a, newsize);
- >
- >No memory loss should occur from this.
-
- Excuse me??? What about if realloc fails?!
- Then you've lost at least the old number of bytes,
- because it returns NULL in that case, overwriting
- the pointer 'a', whose old value is now lost.
-
- You should ALWAYS do this instead:
-
- b = realloc(a, newsize);
- if (b == NULL) {
- /* At least we haven't lost 'a'. */
- }
-
-
- ---
-
- mklenk@coronacorp.com (Mark Klenk)
-
-
-
-